package huawei;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 计算堆栈中的剩余数字
 */
public class Q94 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String str = sc.nextLine();

        List<Integer> nums = Arrays.stream(str.split(" ")).map(String::trim).map(Integer::parseInt).collect(Collectors.toList());


        LinkedList<Integer> stack = new LinkedList<>();

        for (int num : nums) {
            if (stack.isEmpty()) {
                stack.addLast(num);
            } else {
                int sum = num;

                boolean merge = false;
                for (int i = stack.size() - 1; i >= 0; i--) {
                    sum -= stack.get(i);
                    if (sum < 0) {
                        break;
                    } else if (sum == 0) {
                        int time = stack.size() - i;
                        for (int j = 0; j < time; j++) {
                            stack.removeLast();
                        }
                        stack.addLast(num * 2);
                        merge = true;
                    }
                }

                if (!merge) {
                    stack.addLast(num);
                }
            }
        }

        System.out.println(stack);
    }
}
